<template>
  <div></div>
</template>

<script lang="ts">
  import { defineComponent } from 'vue';
  import { useRoute, useRouter } from 'vue-router';

  export default defineComponent({
    name: 'Redirect',
    setup() {
      const { currentRoute } = useRouter();
      const { replace } = useRouter();
      const { params, query } = useRoute();

      const { path, _redirect_type } = params;

      Reflect.deleteProperty(params, '_redirect_type');
      Reflect.deleteProperty(params, 'path');

      const _path = Array.isArray(path) ? path.join('/') : path;

      if (_redirect_type === 'query') {
        let redirect = query._redirect as string;
        Reflect.deleteProperty(query, '_redirect');
        redirect = redirect + '?' + new URLSearchParams(query as any).toString();
        replace(redirect);
      } else {
        replace((_path.startsWith('/') ? '' : '/') + _path);
      }

      return {};
    },
  });
</script> 